package com.java.util;

import com.java.util.pojo.UserA;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

/**
 * list集合截取
 */
public class ListLimit {

    public static void main(String[] args) {

        List<UserA> list = new ArrayList<>();

        for (int i = 0; i < 4; i++) {

            UserA user = new UserA();

            if (i % 2 == 0) {

                user.setAssetId(0);
            } else {
                user.setAssetId(1);

            }

            user.setName(i + "");

            user.setCreatedAt(LocalDateTime.now());
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            list.add(user);
        }

        List<UserA> list1 = list.stream()
                .sorted(Comparator.comparing(UserA::getAssetId).thenComparing(UserA::getCreatedAt))
                .limit(2)
                .collect(Collectors.toList());

        list1.forEach(System.out::println);

        System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ");

        list.forEach(System.out::println);

    }
}
